/******************************************************
 *                                                     
 *              Score System               
 *                                                     
 *******************************************************/

/**
 * AuthorizeFilter.java
 *
 * 权限认证的Filter。这个针对注册用户
 *
 * @author sundy
 * @version 0.0.1
 * lastModified 2011-01-01
 */

package com.sundy.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sundy.core.Context;
import com.sundy.core.Utility;

public class AuthorizeFilter implements Filter {

	public void destroy() {

	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request2 = (HttpServletRequest) request;
		HttpServletResponse response2 = (HttpServletResponse) response;
		Context context = Utility.obtainContext(request2);

		if (context.getCurrentUser() == null) {
			Utility.showError(request2, response2, "该功能需要登录才能使用！");
			return;
		}
		chain.doFilter(request, response);
	}

	public void init(FilterConfig config) throws ServletException {

	}

}
